<?php
	$db = new MySQL();
	$table = "banner";
    $where = "";
	
	//echo $where; die();
	$paging=new paging();
	$mod = $_GET['mod'];
	$curpg = $_GET['curpg'];
	$curpg=(isset($curpg))?$curpg:1;
	$gotopage='?mod='.$mod."&act=list&idcat=".$idcat;
	
	$perpage = 99;
	
	
    $query = "select * from $table $where order by orderId";
	$sql = $db->select($query);
	$totalrows=$db->numrows($sql);

    $query = "select * from $table $where order by orderId limit ".(($curpg-1)*$perpage).", ".$perpage;
    $sql = $db->select($query);

?>


<script type="text/javascript">	
	function add() {
		window.location.href = "?mod=<?=$mod?>&act=numadd";
	}

	function edit(id) {
		var frm = document.frmlist;
		frm.listid.value = id + ",";	
		var listid = frm.listid.value;
		window.location.href = "?mod=<?=$mod?>&act=editlist&listid="+listid;
	}
	
	function editlist() {
		var frm = document.frmlist;
		if (<?=$totalrows?> != 0)		
		frm.listid.value=selectid(frm.chkid);		
		if (frm.listid.value=="") {		
			if (<?=$totalrows?> != 0)				
			alert("<?=$msg_ask_select?>");
		}	
		else {
			var listid = frm.listid.value;
			window.location.href = "?mod=<?=$mod?>&act=editlist&listid="+listid;
		}		
	}

	function del(id) {
		var frm = document.frmlist;
		bok=confirm("<?=$msg_deleteone?>");
		if (bok) {		
			frm.listid.value = id + ",";			
			frm.action = "?mod=<?=$mod?>&act=process";
			frm.submit();
		}
	}
	
	function delall(id) {
		var frm = document.frmlist;
		if (<?=$totalrows?> != 0)		
		frm.listid.value=selectid(frm.chkid);		
		if (frm.listid.value=="") {		
			if (<?=$totalrows?> != 0)				
			alert("<?=$msg_ask_select?>");
		}	
		else {
			bok=confirm("<?=$msg_conf_del?>");
			if (bok) {					
				frm.action = "?mod=<?=$mod?>&act=process";				
				frm.submit();
			}
		}		
	}
	
	function submitfrm(idcat) {			
		window.location.href = "?mod=<?=$mod?>&act=list&idcat="+idcat;
	}
</script>

<script type="text/javascript" src="scriptaculous/prototype.js"></script>  
    <script type="text/javascript" src="scriptaculous/scriptaculous.js"></script>  
    <script type="text/javascript">  
    //<![CDATA[  
        document.observe('dom:loaded', function() {  
            var changeEffect;  
            Sortable.create('sortlist', { tag: 'li', overlap:'horizontal',constraint:false,   
                onChange: function(item) {  
                    var list = Sortable.options(item).element;  
                    //$('changeNotification').update(Sortable.serialize(list).escapeHTML());  
                    if(changeEffect) changeEffect.cancel();  
                    changeEffect = new Effect.Highlight('changeNotification', {restoreColor:"transparent" });  
                },  
                      
                onUpdate: function() {  
                    new Ajax.Request("<?=$mod?>_order.php", {  
                        method: "post",  
                        onLoading: function(){$('activityIndicator').show()},  
                        onLoaded: function(){$('activityIndicator').hide()},  
                        parameters: { data: Sortable.serialize("sortlist") }  
                    });  
                }                 
            });  
        });  
    // ]]>  
    </script>  
<style>
	li { list-style:none; cursor:move; float:left; }	
	li .img { width:150px; height:50px; overflow:hidden; margin:8px;}
</style>	
	

<form name="frmlist" method="post" action="">		
<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
	  <td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
		  <tr>
			<td width="34"><img src="<?=APPLICATION_SITEADMIN_URL?>images/cor_data_top_l.gif" alt="tl" width="34" height="19" /></td>
			<td class="toptborder">&nbsp;</td>
			<td width="20"><img src="<?=APPLICATION_SITEADMIN_URL?>images/cor_data_top_r.gif" alt="tr" /></td>
		  </tr>
	  </table></td>
	</tr>
	<tr>
	  <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
		 
		  <tr>
			<td width="10" class="leftborder">&nbsp;</td>
			<td><table width="100%" border="0" cellpadding="0" cellspacing="0" class="dataBack">
				  <tr>
				  <td width="30%" height="36" class="titleOrange">Banner</td>
				  <td align="right" valign="middle">		 </td>				 	
				</tr>
				<tr>
			  	  <td><a href="javascript:docheckallnew(false, document.frmlist.chkid)" >Deselect All</a> | <a href="javascript:docheckallnew(true, document.frmlist.chkid)" >Select All</a></td>
				  <td align="right" style="padding-bottom:5px;">
				  <img src="images/icons/add.png" onclick="add();" class="pointer"/> <img src="images/icons/editbtn.png" onclick="editlist();" class="pointer" /> <img src="images/icons/delete.png" onclick="delall();" class="pointer"/> 
				</td>
			    </tr>				
				<tr>
				  <td height="7" colspan="2" background="images/cor_data_line1.gif"></td>
				</tr>
				<tr>
				  <td colspan="2">
				  <table width="100%" border="0" cellspacing="0" cellpadding="0">
					
					  <tr>
						<td colspan="5" class="dataBack2"><table width="100%" border="0" align="left" cellpadding="0" cellspacing="0">
							<tr>
							  <td align="left" valign="top" ><table width="100%" border="0" cellspacing="0">
								  <tr>
									<td >
									<table width="100%" border="0" cellpadding="0" cellspacing="1" class="gridtitle">
										<tr>
											<td class="gridtitletitle">&nbsp; Banner</td>
									    </tr>
												
										<tr class="<?=$listitem?>" onMouseOver="mOvr(this,'bgover')" onMouseOut="mOut(this,'<?=$listitem?>')">
										  <td>
											
											<div id="changeNotificationNo"> </div>  
											<div id="sortlist" style="margin:auto;">
											<?php
											if ($totalrows!=0)
											{
												$i=1;
												while ($row = $db->fetch($sql))
												{
												
											?>
											<li  id="pictureId_<?=$row['id']?>">
											<div class="img"><img src="<?=APPLICATION_URL?>banner-img/<?=$row['image']?>"  width="150px" /></div> 
											<input type="checkbox" name="chkid" value="<?=$row["id"]?>" />
											<img src="images/icons/edit.png" onclick="edit('<?=$row["id"]?>')" class="pointer"/>&nbsp;&nbsp;&nbsp;<img src="images/icons/del.png" onclick="del('<?=$row["id"]?>')" class="pointer" />
</li>	
											
											<?
												  $i++;
												}
											}
											?>	
											</div>											</td>	
									    </tr>
																						
									</table></td>

								  </tr>
								  <tr>
									<td><table width="100%" border="0" cellspacing="0">
										<tr>
										  <td width="68%" align="left" valign="middle" class="titlepage"><?=$lb_tottalrow?>  <span class="numpage"><?=$totalrows?></span> </td>
										  <td width="32%" align="right" valign="top" class="numpage"><? echo $paging->pagenew($totalrows, $perpage, $pagecount, $curpg, $gotopage, "","titlepage");?></td>
										</tr>

									</table></td>
								  </tr>
							  </table></td>
							</tr>
						</table></td>
					  </tr>
					  <tr>
						<td height="15" colspan="5"></td>
					  </tr>
				  </table>
				  </td>
				</tr>
			</table></td>
			<td width="10" class="rightborder">&nbsp;</td>
		  </tr>
	  </table></td>
	</tr>
	<tr>
	  <td><table width="100%" border="0" cellpadding="0" cellspacing="0" class="dataBack">
		  <tr>
			<td width="34"><img src="<?=APPLICATION_SITEADMIN_URL?>images/cor_data_bot_l.gif" alt="bl" /></td>
			<td class="botborder" >&nbsp;</td>
			<td width="19"><img src="<?=APPLICATION_SITEADMIN_URL?>images/cor_data_bot_r.gif" alt="br" /></td>
		  </tr>
	  </table></td>
	</tr>
</table>
<input type="hidden" name="form_" value="delete" />		
<input type="hidden" name="listid" value="" />
<input type="hidden" name="curpg" value="<?=$curpg?>" />
</form>		
	
<?php
	$db->close();
?>
